package com.giantlizard.cloud.mybatis.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private String ID_FIELD_NAME = "id";
    private String CREATE_TIME_FIELD_NAME = "createDate";
    private String CREATE_BY_FIELD_NAME = "createBy";
    private String MODIFY_TIME_FIELD_NAME = "updateDate";
    private String MODIFY_BY_FIELD_NAME = "updateBy";
    private String CREATE_ORG_ID_FIELD_NAME = "createOrgId";
    private String CREATE_ORG_NAME_FIELD_NAME = "createOrgName";
    private String CREATE_USERNAME_FIELD_NAME = "creatorname";
    private String MODIFY_USERNAME_FIELD_NAME = "modifiername";
    private String TENANT_ID_FIELD_NAME = "tenantId";
    private String DEL_FLAG_FIELD_NAME = "delFlag";
    private String STATUS_NAME_FIELD_NAME = "statusName";
    private String STATUS_FIELD_NAME = "status";
    private String DATA_LOCK_FIELD_NAME = "dataLock";
    private String VERSION_FIELD_NAME = "version";

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "id", Long.class, 1L);
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }
}